<template>
  <div :class="className" :style="{height:height,width:width}"/>
</template>

<script>
require('echarts/theme/macarons')
import resize from '@/components/Charts/mixins/resize'
export default {
  name: 'BioLineChart',
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '260px'
    }
  },
  data() {
    return {
      chart: null,
      timeArray: [],
      confidenceOfFace: [],
      confidenceOfFingerPrint: [],
      confidenceOfOther: []
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
      this.getData()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(this.$el, 'macarons')
      const initOption = {
        // title: '最近一周内认证置信度' ,
        title: {
          show: true,
          text: '一周内认证置信度',
          textStyle: {
            color: 'black'
          }
        },
        tooltip: {
          trigger: 'axis',
          backgroundColor: 'rgba(255,255,255,0.8)', // 设置背景图片 rgba格式
          color: 'black',
          borderWidth: '1', // 边框宽度设置1
          borderColor: 'gray', // 设置边框颜色
          textStyle: {
            color: 'black' // 设置文字颜色
          }
        },
        legend: {
          data: ['人脸识别', '指纹识别', '其他'],
          // orient: 'vertical',
          // top: 0,
          right: 2
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true // 在计算这些距离时是否加入标签
        },
        xAxis: {
          type: 'category'
          // boundaryGap: false
          // rotate: true
          // 这里改为过去7天的平均置信度
          // data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        },
        yAxis: {
          type: 'value',
          // scale: true
          min: 80,
          max: 100,
          interval: 2
        },
        series: [
          {
            // 同个类目轴上配置了相同的stack值后，后一个系列的值就会在前一个的值上相加
            name: '人脸识别',
            type: 'line',
            // stack: '总量',
            // 这个主题默认smooth为true
            smooth: false
          },
          {
            name: '指纹识别',
            type: 'line',
            // stack: '总量',
            smooth: false
          },
          {
            name: '其他',
            type: 'line',
            // stack: '总量',
            smooth: false
          }
        ]
      }
      this.chart.setOption(initOption)
    },
    getData() {
      // 第一个是过去的时间，后面几个是对应的数据，故长度应该是1+3=4
      this.timeArray = ['2021/08/26', '2021/08/27', '2021/08/28', '2021/08/29', '2021/08/30', '2021/08/31', '2021/09/01']
      this.confidenceOfFingerPrint = ['98', '95', '96', '97', '98', '96', '97']
      this.confidenceOfFace = ['96', '97', '92', '98', '99', '94', '96']
      this.confidenceOfOther = ['93', '94', '92', '96', '95', '93', '94']
      this.updateChart()
    },
    updateChart() {
      const updateOption = {
        xAxis: {
          data: this.timeArray
        },
        series: [
          { data: this.confidenceOfFace },
          { data: this.confidenceOfFingerPrint },
          { data: this.confidenceOfOther }
        ]
      }
      this.chart.setOption(updateOption)
    }
  }
}
</script>

<style scoped>

</style>
